package life.system.product.controller;

import java.util.Arrays;
import java.util.Map;

import life.system.common.vo.SkuInfoVo;
import life.system.product.vo.SkuDetailResult;
import life.system.product.vo.SkuSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import life.system.product.entity.SkuInfoEntity;
import life.system.product.service.SkuInfoService;
import life.system.common.utils.PageUtils;
import life.system.common.utils.R;


@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = skuInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SkuInfoVo skuInfo = skuInfoService.getBySkuId(id);
        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuSaveVo vo) {
        skuInfoService.saveSpuInfo(vo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        skuInfoService.productRemoveByIds(ids);

        return R.ok();
    }


    /**
     * 商品上架
     */
    @PostMapping("/{skuId}/up")
    public R spuUp(@PathVariable("skuId") Long skuId) {
        skuInfoService.up(skuId);
        return R.ok();
    }

    @RequestMapping("/{skuId}/detail")
    public R detail(@PathVariable("skuId") Long skuId) {
        SkuDetailResult data = skuInfoService.detail(skuId);
        return R.ok().put("data", data);
    }
}
